import { Entity, Column, PrimaryGeneratedColumn, AfterInsert, ManyToOne, ManyToMany } from 'typeorm'
import { IsEmail, IsNotEmpty, Matches } from 'class-validator'
import { Base } from './Base'
import { User } from './User';

@Entity()
export class Role extends Base {
  @Column({
    nullable: false,
    unique: true,
  })
  @IsNotEmpty()
  public name!: string

  @Column({
    length: 1024,
    nullable: false,
  })
  public description!: string;

  @ManyToMany(() => User, user => user.roles, { onDelete: 'CASCADE' })
  public users!: User[];

}
